package com.nti56.springboot.service;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.nti56.springboot.mapper.tmsmapper.RoleMapper;
import com.nti56.springboot.model.Role;

@Service
public class RoleService {
	
	private static final Logger logger = LoggerFactory.getLogger(RoleService.class);

	
	@Autowired
    private RoleMapper roleMapper;
	
	public List<Role> findAll(Map params) {
		return roleMapper.findAll(params);
	}
	
	public List<Role> getRoleList(Map params) {
		return roleMapper.getRoleList(params);
	}
	
	public Role getRoleByRoleId(String id) {
		return roleMapper.getById(id);
	}
	
	@Transactional(rollbackFor = Exception.class, transactionManager = "tmsTransactionManager") 
	public void addRole(Role role){
		roleMapper.insert(role);
	}
	
	@Transactional(rollbackFor = Exception.class, transactionManager = "tmsTransactionManager") 
	public void updateRole(Role role){
		roleMapper.update(role);
	}
	
	@Transactional(rollbackFor = Exception.class, transactionManager = "tmsTransactionManager") 
	public void deleteRole(String roleId){
		roleMapper.deleteResourceRoleByRoleId(roleId);
		roleMapper.deleteUserRoleByRoleId(roleId);
		roleMapper.delete(roleId);
	}
}
